﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using System.Security.Cryptography.X509Certificates;

namespace NHINDirect
{
    /// <summary>
    /// Scenario: The organization uses a single uber certificate to establish identity and secure communications
    /// </summary>
    public class UniformCertificateService : UniformCertificateStore, ICertificateService
    {
        public UniformCertificateService(X509Certificate2 cert)
            : base(cert)
        {
        }
                
        public override X509Certificate2 Certificate
        {
            get
            {
                return base.Certificate;
            }
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException();
                }

                if (!value.HasPrivateKey)
                {
                    throw new ArgumentException("No private key in cert");
                }

                base.Certificate = value;
            }
        }

        public X509Certificate2 GetPrivateCertificate(MailAddress address)
        {
            if (address == null)
            {
                throw new ArgumentNullException();
            }
            
            return this.Certificate;
        }
    }
}
